Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cctp submitter race #2853

Merged
merged 2 commits into from
Jul 8, 2024
Merged

fix cctp submitter race #2853

merged 2 commits into from
Jul 8, 2024

Conversation

trajan0x
Copy link
Contributor

@trajan0x trajan0x commented Jul 7, 2024

Description

fixes submitter race

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling during transaction submission to prevent multiple instances from starting simultaneously, enhancing stability and reliability.

Copy link
Contributor

coderabbitai bot commented Jul 7, 2024

Walkthrough

The recent changes enhance error handling in the Run and Start methods of the CCTPRelayer and Relayer structs, respectively. Specifically, the updates ensure that these methods check if the transaction submitter has already started before attempting to start it, preventing redundant operations and managing errors based on the current state of the submitter.

Changes

File Path Change Summary
services/cctp-relayer/.../relayer.go Added error handling in Run method to check if the submitter has already started.
services/rfq/relayer/.../relayer.go Enhanced Start method to verify if the submitter is already active and manage errors accordingly.

Poem

In code's vast and intricate maze,
We now enhance the relayer's phase.
Check once, start once, avoid the repeat,
Ensuring operations are ever neat.
With thoughtful handling, errors dispense,
Our relayers now run with common sense!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Jul 7, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

  • Addressed race condition in transaction submitter
  • Added check to ensure submitter starts only once

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 25.65620%. Comparing base (2d8fd40) to head (307513e).

Files Patch % Lines
services/rfq/relayer/service/relayer.go 0.00000% 6 Missing ⚠️
services/cctp-relayer/relayer/relayer.go 50.00000% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2853         +/-   ##
===================================================
+ Coverage   25.65579%   25.65620%   +0.00040%     
===================================================
  Files            768         768                 
  Lines          55239       55242          +3     
  Branches          80          80                 
===================================================
+ Hits           14172       14173          +1     
- Misses         39594       39596          +2     
  Partials        1473        1473                 
Flag Coverage Δ
cctp-relayer 31.97848% <50.00000%> (+0.04068%) ⬆️
opbot 0.18564% <ø> (ø)
rfq 24.93553% <0.00000%> (-0.00805%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Jul 7, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 307513e
Status: ✅  Deploy successful!
Preview URL: https://006c24c1.sanguine-fe.pages.dev
Branch Preview URL: https://fix-submitter-bug.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

  • Added check to ensure transaction submitter starts only once in /services/rfq/relayer/service/relayer.go
  • Improved error handling for transaction submission
  • Enhanced reliability of transaction submission by preventing redundant start attempts

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d8fd40 and a5f075c.

Files selected for processing (1)
  • services/cctp-relayer/relayer/relayer.go (2 hunks)
Additional comments not posted (3)
services/cctp-relayer/relayer/relayer.go (3)

308-308: Check if the transaction submitter is already started.

This line adds a condition to check if the transaction submitter is already started before attempting to start it. This is a good practice to avoid redundant operations.


309-312: Handle errors gracefully when starting the transaction submitter.

These lines handle errors more gracefully by only returning an error if the submitter fails to start and the error is not due to the submitter already being in a started state. This prevents the method from failing due to an already started submitter.


314-314: Ensure consistent return of nil in the goroutine.

This line ensures that the goroutine returns nil if the transaction submitter is already started or successfully started. This maintains consistency in the error handling and return values of the goroutines.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d8fd40 and 307513e.

Files selected for processing (2)
  • services/cctp-relayer/relayer/relayer.go (2 hunks)
  • services/rfq/relayer/service/relayer.go (2 hunks)

Comment on lines +308 to +312
if !c.txSubmitter.Started() {
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error Handling Improvement: Check if txSubmitter has already started.

The added check ensures that the transaction submitter is not started multiple times, preventing redundant operations and potential errors. However, the conditional block can be simplified for better readability.

-		if !c.txSubmitter.Started() {
-			err := c.txSubmitter.Start(ctx)
-			if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
-				return fmt.Errorf("could not start tx submitter: %w", err)
-			}
-		}
+		if c.txSubmitter.Started() {
+			return nil
+		}
+		err := c.txSubmitter.Start(ctx)
+		if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
+			return fmt.Errorf("could not start tx submitter: %w", err)
+		}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !c.txSubmitter.Started() {
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}
if c.txSubmitter.Started() {
return nil
}
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}

Comment on lines +241 to +246
if !r.submitter.Started() {
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error Handling Improvement: Check if submitter has already started.

The added check ensures that the transaction submitter is not started multiple times, preventing redundant operations and potential errors. However, the conditional block can be simplified for better readability.

-		if !r.submitter.Started() {
-			err := r.submitter.Start(ctx)
-			if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
-				return fmt.Errorf("could not start submitter: %w", err)
-			}
-			return nil
-		}
+		if r.submitter.Started() {
+			return nil
+		}
+		err := r.submitter.Start(ctx)
+		if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
+			return fmt.Errorf("could not start submitter: %w", err)
+		}
+		return nil
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !r.submitter.Started() {
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil
if r.submitter.Started() {
return nil
}
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil

@trajan0x trajan0x merged commit 31b5f8f into master Jul 8, 2024
36 checks passed
@trajan0x trajan0x deleted the fix/submitter-bug branch July 8, 2024 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant